home *** CD-ROM | disk | FTP | other *** search
-
- /*⌐ Copyright 1988-1991 UserLand Software, Inc. All Rights Reserved.*/
-
-
- #include "appletinternal.h"
- #include "ops.h"
- #include "quickdraw.h"
- #include "appletmain.h"
- #include "printing.h"
-
-
- static disposeprintinfo (void) {
-
- disposehandle ((Handle) app.printinfo.printhandle);
-
- clearbytes (&app.printinfo, longsizeof (app.printinfo));
- } /*disposeprintinfo*/
-
-
- static boolean checkprinterror (void) {
-
- /*
- returns false if there was a print error.
- */
-
- short x;
- bigstring bserror, bs;
-
- x = PrError ();
-
- if (x == noErr) /*no error, keep going*/
- return (true);
-
- if (x != iPrAbort)
- appalert ("\pPrinting error.");
-
- return (false); /*there was an error*/
- } /*checkprinterror*/
-
-
- static copyprintinfo (void) {
-
- Rect r;
-
- r = app.printinfo.paperrect = (**(THPrint) app.printinfo.printhandle).prInfo.rPage;
-
- app.printinfo.vpagepixels = r.bottom - r.top;
- } /*copyprintinfo*/
-
-
- boolean initprint (void) {
-
- Handle h;
- Rect r;
-
- clearbytes (&app.printinfo, longsizeof (app.printinfo));
-
- if (!newclearhandle (longsizeof (TPrint), &h))
- return (false);
-
- app.printinfo.printhandle = h; /*copy into print record*/
-
- PrOpen (); /*initialize the Mac print manager*/
-
- if (!checkprinterror ())
- goto error;
-
- PrintDefault ((THPrint) app.printinfo.printhandle); /*set default print record*/
-
- PrClose (); /*shouldn't leave print resources open all the time*/
-
- if (!checkprinterror ())
- goto error;
-
- copyprintinfo (); /*copies fields from handle into record*/
-
- return (true);
-
- error:
-
- disposeprintinfo ();
-
- return (false);
- } /*initprint*/
-
-
- static boolean pagesetupvisit (hdlappwindow appwindow) {
-
- setappwindow (appwindow);
-
- (*app.pagesetupcallback) ();
- } /*pagesetupvisit*/
-
-
- boolean pagesetup (void) {
-
- PrOpen ();
-
- if (!checkprinterror ())
- return (false);
-
- PrValidate ((THPrint) app.printinfo.printhandle);
-
- PrStlDialog ((THPrint) app.printinfo.printhandle);
-
- PrClose ();
-
- if (!checkprinterror ())
- return (false);
-
- copyprintinfo (); /*copies fields from handle into record*/
-
- visitappwindows (&pagesetupvisit);
- } /*pagesetup*/
-
-
- boolean printappwindow (hdlappwindow appwindow, boolean fldialog) {
-
- TPPrPort printport;
- TPrStatus printstatus;
- short i;
- register boolean fl;
-
- setappwindow (appwindow);
-
- PrOpen ();
-
- if (!checkprinterror ())
- return (false);
-
- fl = false; /*until sucessfull print, this is return value*/
-
- if (fldialog) {
-
- if (!PrJobDialog ((THPrint) app.printinfo.printhandle))
- goto exit;
-
- serviceeventqueue (); /*update all dirtied windows*/
- }
- else
- PrValidate ((THPrint) app.printinfo.printhandle);
-
- watchcursor ();
-
- copyprintinfo ();
-
- (*app.openprintcallback) (); /*fills in fields of printinfo record*/
-
- pushmacport (nil); /*save current port on stack*/
-
- printport = PrOpenDoc ((THPrint) app.printinfo.printhandle, nil, nil);
-
- for (i = 1; i <= app.printinfo.ctpages; i++) { /*print one page*/
-
- if (!serviceeventqueue ()) /*user must have selected quit or something like that*/
- PrSetError (iPrAbort);
-
- if (PrError () != noErr)
- break;
-
- PrOpenPage (printport, nil);
-
- if (PrError () == noErr) {
-
- SetFractEnable (true);
-
- fl = (*app.printpagecallback) (i);
-
- SetFractEnable (false);
- }
-
- PrClosePage (printport);
-
- if (!fl)
- break;
- } /*for*/
-
- PrCloseDoc (printport);
-
- if (fl) {
-
- if (PrError () == noErr)
- PrPicFile ((THPrint) app.printinfo.printhandle, nil, nil, nil, &printstatus);
-
- fl = checkprinterror ();
- }
-
- popmacport ();
-
- exit:
-
- (*app.closeprintcallback) ();
-
- PrClose ();
-
- return (fl);
- } /*printappwindow*/
-
-
-